#include <fstream>
#include <iostream>
#include <ctime>

using namespace std;

void read_from_file(string file_name, int array[], int size) {
    
    ifstream fin;
    fin.open(file_name);
    for (int i = 0; i < size; i++) {
        fin >> array[i]; 
    }

}


void sort(int array[], int size) {
    for (int j = 0; j < size-1; j++) {
        bool swap = false;
        for (int i = 0; i < size-1-j; i++) {
            if (array[i] > array[i+1]) {
                int c =  array[i];
                array[i] = array[i+1];
                array[i+1] = c;
                swap = true;
            }
        
        }
        if (swap == false) {
            return;
        }
    }
}



void print (int array[], int size) {
     for (int i = 0; i < size; i++) {
         cout << array[i] << " ";
     }
}


int main() {
    
    int SIZE = 5000;
    int ar[SIZE];
    
    read_from_file("m1_sorted.txt", ar, SIZE);
    int t1 = clock();
    sort(ar, SIZE);
    int t2 = clock();
    cout << "m1_sorted.txt " <<(t2-t1) * 1000 / CLOCKS_PER_SEC <<" milliseconds\n";
    
    read_from_file("m2_reverse.txt", ar, SIZE);
    t1 = clock();
    sort(ar, SIZE);
    t2 = clock();
    cout << "m2_reverse.txt "<< (t2-t1) * 1000 / CLOCKS_PER_SEC <<" milliseconds\n";
    
    read_from_file("m3_shuffle.txt", ar, SIZE);
    t1 = clock();
    sort(ar, SIZE);
    t2 = clock();
    cout << "m3_shuffle.txt " << (t2-t1) * 1000 / CLOCKS_PER_SEC <<" milliseconds";
    return 0;
}
